﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace 智信科技物流系统
{
    public class SearchClass
    {
        public string TrimStr(string str, string type)
        {

            int flog = 0;   //判断分号连续出现的次数，如果分号连续出现，则向用户提示检查Key，或者重新输入
            str.Trim();
            if (str.Trim() == "" || str.Trim() == null)
            {
                MessageBox.Show("信息不能为空");
                return null;
            }

            if (str[0] == ';' || str[0] == '；')
            {

                MessageBox.Show("关键字开头不能使用分隔符，请检查后重新输入");
                return null;

            }

            if (str[str.Length - 1] == ';' || str[str.Length - 1] == '；')
            {
                MessageBox.Show("关键字结尾不能使用分隔符，请检查后重新输入");
                return null;
            }


            str = ("'%" + str + "%'").Trim();
            int len = str.Length;
            string savestr = null; //  用来保存新的字符串，最后返回出去

            try
            {
                for (int i1 = 0; i1 < len; i1++)
                {
                    if (flog < 2 && flog >= 0)
                    {
                        if (str[i1] == ';' || str[i1] == '；')
                        {
                            flog++;
                            savestr = (savestr + "%' or " + type.Trim() + " like '%").Trim();
                        }
                        else
                        {
                            if (flog > 0)
                            {
                                flog--;
                            }
                            savestr = (savestr + str[i1]).Trim();
                        }

                    }

                    else
                    {
                        MessageBox.Show("您连续输入了分号，请检查后重新输入");
                        return null;
                    }
                }
                return savestr;
            }
            catch
            {
                MessageBox.Show("数据加载错误或操作错误，请重试");
                return null;
            }
        }
        public string Package(string strstartadd, string strkey)
        {
            try
            {
                DateTime t = DateTime.Now.Date;
                t = t.AddDays(-2);//获取十天以内的全部信息
                string str = null;
                str = "select * from bm_Release where ( InformationContent like " + strkey + " ) and ( DepartureCity like " + strstartadd + " )and ( DepartureTime > '" + t.ToString("yyyy-MM-dd HH:mm") + "') order by id asc";
                return str;
            }
            catch
            {
                return null;
            }
        }
        public string Package(string strstartadd, string strendadd, string strkey)
        {
            try
            {
                DateTime t = DateTime.Now.Date;
                t = t.AddDays(-2);//获取十天以内的全部信息

                string str = null;
                str = "select * from bm_Release where ( InformationContent like " + strkey + " ) and ( DepartureCity like " + strstartadd + " ) and ( ReachCity like " + strendadd + " ) and ( DepartureTime > '" + t.ToString("yyyy-MM-dd HH:mm") + "') order by id asc";
                return str;
            }
            catch
            {
                return null;
            }
        }

    }
}
